package com.aricksm.xuan.activaty02;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Created by xuan on 16/6/27.
 */
public class ListViewActivity extends Activity implements AdapterView.OnItemClickListener {

    ListView lv1;
    ListView lv2;
    ListView lv3;

    private Context mContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview2);
        mContent = this;
        lv1 = (ListView) findViewById(R.id.lv_1);
        lv2 = (ListView) findViewById(R.id.lv_2);
        lv3 = (ListView) findViewById(R.id.lv_3);

        myListViewAdapter listAdapter = new myListViewAdapter();

        lv1.setAdapter(listAdapter);
        lv2.setAdapter(listAdapter);
        lv3.setAdapter(listAdapter);

        lv1.setOnItemClickListener(this);


    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //需要获取条目上bean对象中url做跳转
        NewsBean bean = (NewsBean) parent.getItemAtPosition(position);

        String url = bean.news_url;

        //跳转浏览器
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        startActivity(intent);
    }



    class myListViewAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView textview = null;
            if(convertView != null){
                textview = (TextView) convertView;
            }else{
                textview = new TextView(mContent);
            }
            textview.setText("position"+position);
            textview.setTextSize(50);
            return textview;
        }

    }




}
